package ch.zbw.pra.sysventory.domain.visualisation;

import java.util.ArrayList;
import java.util.List;

import ch.zbw.pra.sysventory.domain.model.Nic;

public class VisuControllNIC extends AVisuControll implements IVisuControll<Nic> {

	private boolean nicBez;
	private boolean ipV4;
	private boolean ipV6;
	private boolean mac;
	private boolean subnet;
	private boolean gateway;
	private boolean dhcp;

	public VisuControllNIC() {
		super();
	}

	public boolean isNicBez() {
		return this.nicBez;
	}

	public void setNicBez(boolean nicBez) {
		this.nicBez = nicBez;
		updateObserver();
	}

	public boolean isIpV4() {
		return this.ipV4;
	}

	public void setIpV4(boolean ipV4) {
		this.ipV4 = ipV4;
		updateObserver();
	}

	public boolean isIpV6() {
		return this.ipV6;
	}

	public void setIpV6(boolean ipV6) {
		this.ipV6 = ipV6;
		updateObserver();
	}

	public boolean isMac() {
		return this.mac;
	}

	public void setMac(boolean mac) {
		this.mac = mac;
		updateObserver();
	}

	public boolean isSubnet() {
		return this.subnet;
	}

	public void setSubnet(boolean subnet) {
		this.subnet = subnet;
		updateObserver();
	}

	public boolean isGateway() {
		return this.gateway;
	}

	public void setGateway(boolean gateway) {
		this.gateway = gateway;
		updateObserver();
	}

	public boolean isDhcp() {
		return this.dhcp;
	}

	public void setDhcp(boolean dhcp) {
		this.dhcp = dhcp;
		updateObserver();
	}

	public void addDataToRow(List<Nic> data, List<List<String>> row) {
		if (isNicBez()) {
			row.add(makeNicNameList(data));
		}
		if (isIpV4()) {
			row.add(makeNicV4List(data));
		}
		if (isIpV6()) {
			row.add(makeNicV6List(data));
		}
		if (isMac()) {
			row.add(makeNicMacList(data));
		}
		if (isSubnet()) {
			row.add(makeNicSubnetList(data));
		}
		if (isGateway()) {
			row.add(makeNicGatewayList(data));
		}
		if (isDhcp()) {
			row.add(makeNicHasDHCPList(data));
		}
	}

	public void addDataToColumn(List<String> data) {
		if (isNicBez()) {
			data.add("NIC Bezeichnung");
		}
		if (isIpV4()) {
			data.add("IPv4");
		}
		if (isIpV6()) {
			data.add("IPv6");
		}
		if (isMac()) {
			data.add("MAC Adresse");
		}
		if (isSubnet()) {
			data.add("Subnetz Maske");
		}
		if (isGateway()) {
			data.add("Gateway");
		}
		if (isDhcp()) {
			data.add("Hat DHCP");
		}
	}

	private List<String> makeNicNameList(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.getNameNic());
		}
		return data;
	}

	private List<String> makeNicV4List(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.getIpv4Nic());
		}
		return data;
	}

	private List<String> makeNicV6List(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.getIpv6Nic());
		}
		return data;
	}

	private List<String> makeNicMacList(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.getMacAdressNic());
		}
		return data;
	}

	private List<String> makeNicSubnetList(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.getSubnetNic());
		}
		return data;
	}

	private List<String> makeNicGatewayList(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.getStandardGatewayNic());
		}
		return data;
	}

	private List<String> makeNicHasDHCPList(List<Nic> nic) {
		List<String> data = new ArrayList<String>();
		for (Nic network : nic) {
			data.add(network.isDhcpNic());
		}
		return data;
	}

	public void restoreTo(boolean value) {
		this.nicBez = value;
		this.ipV4 = value;
		this.ipV6 = value;
		this.mac = value;
		this.subnet = value;
		this.gateway = value;
		this.dhcp = value;

	}
}
